/**
 * 
 */
package cn.jhz.filesharingsystem.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.jhz.filesharingsystem.model.Pager;
import cn.jhz.filesharingsystem.model.Permission;

/**
 * PermissionDao的实现类
 * @author asus
 */
@Repository("permissionDao")
public class PermissionDaoImpl extends BaseDaoImpl<Permission> implements PermissionDao {

	@Override
	public List<Permission> getAllPermission(boolean state) {
		String hql = "FROM Permission p where p.state=1";
		if(state) {
			hql+="AND p.resource !='/permissions_list' AND p.resource !='/permission' AND p.resource !='/permissions' AND p.resource !='/permission_management' ";
		}
		return super.list(hql, null, null);
	}

	@Override
	public Pager<Permission> getAllPagerPermission() {
		String hql = "FROM Permission";
		return super.find(hql, null, null);
	}

	@Override
	public boolean isExistResource(String url) {

		String hql = "SELECT COUNT(*) FROM Permission p WHERE p.resource=?0";
		long count = (long) super.queryByHql(hql, new Object[] {url}, null);
		
		return count > 0 ? true:false;
	}

}
